Digital computers commonly use dirty bits to enhance performance of memory systems. In particular, virtual memory is a feature present in all modern computers. These computers include a module usually called the Memory Management Controller (or Unit) (MMC or MMU), which enables the use of virtual memory. The MMC allows the operating system (OS) to split the memory allocated for each process into fixed size memory pages and place these pages anywhere in the actual memory (RAM). The MMC then provides on-the-fly translations of the logical (or virtual) memory addresses referenced by the processor instructions into the corresponding physical addresses.
When the physical memory is not large enough to hold all the pages for all the processes running at the same time, the OS can temporarily store (page out) some of them on peripheral memory (usually a hard disc). When a running process references a page that is out, the MMC generates an exception to the OS, which should then allocate a page of physical memory and read its contents from the disc before resuming the process' execution. If there are no physical memory pages available, the OS releases other pages, possibly saving their contents to disc.
The MMC usually has several functions that help the OS optimise this memory management. If a memory page has not been modified since it was loaded from the disc, it does not need to be saved to disc when the OS needs to reuse that page for another process. The OS can simply de-allocate the page.
When the processor or a ny other device writes on a memory page, a special bit on the MMC hardware is set to indicate that the page contents were modified. Such bits exist for every physical memory page present on the system, and are usually called dirty bits, as memory pages that have been modified are commonly said to be “dirty”. When the operating system needs to reuse a page, it checks this bit to learn if the page is dirty. If it is not, the page can simply be discarded, avoiding unnecessary rewriting of the non-modified contents to disc. If the page is dirty, it must be saved and the dirty bit can then be reset.
These dirty bits are managed by the OS and are usually invisible to applications and processes running outside of the OS's kernel. However, this detection of memory page content modification implemented in hardware can also be used for optimising other algorithms which are usually implemented at the application level, the most notable example being memory garbage collection. Garbage collectors allow applications to dynamically allocate memory blocks without the need to explicitly release them when they are not needed any more. The garbage collection algorithm frequently inspects the processes' memory space to identify blocks that are no longer being referenced. Such blocks can be returned to a free memory pool to be reallocated when the need arises.
The garbage collection could be considerably optimised if the collector knew which portions of a process' memory space have been modified since the last garbage collection cycle occurred. If a given memory block has not been modified since then, it does not need to be scanned again to look for blocks not being referenced. To do this a mechanism similar to the dirty bit would be needed at the application level.
U.S. Pat. No. 4,989,134 describes a system for enhancing these mechanisms. The system creates a saved state map that prevents the garbage collector from interfering with the virtual memory tasks. A memory manager checks both a primary dirty page map and the saved state map to determine whether a page is clean or dirty. However, there are only two dirty bits (including backup dirty bits) for each page in primary memory, and the memory manager and garbage collector do not set or reset each other's dirty bits. This means that the system cannot be extended to a larger number of applications.